package com.example.wm.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.wm.common.Result;
import com.example.wm.common.ResultData;
import com.example.wm.entity.BaoxiaoMx;

import com.example.wm.mapper.ReimbursementDetailsMapper;
import com.example.wm.mapper.ReimbursementMapper;
import com.example.wm.service.ReimbursementDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/ReimbursementDetails")
public class ReimbursementDetailsController {

    @Resource
    private ReimbursementDetailsService reimbursementDetailsService;
    @Resource
    private ReimbursementDetailsMapper reimbursementDetailsMapper;
    @PostMapping("/getList")
    public Result<List> getReimbursementList(@RequestBody JSONObject jsonObject){
        Integer id=jsonObject.getInteger("id");
        LambdaQueryWrapper<BaoxiaoMx> lq=new LambdaQueryWrapper<>();
        lq.eq(BaoxiaoMx::getReimbid,id);
        List<BaoxiaoMx> l1=reimbursementDetailsMapper.selectList(lq);


        return  ResultData.success("操作成功",l1);
    }
    //保存
    @PostMapping ("/save")
    public Result<Integer> saveReimbursementList(@RequestBody BaoxiaoMx bx) {

        reimbursementDetailsService.save(bx);
        System.out.println(bx.getId());
        return ResultData.success( bx.getId());
    }
    //删除
    @PostMapping ("/delete")
    public Result<Integer> deleteReimbursementList(@RequestBody JSONObject jsonObject) {
        LambdaQueryWrapper<BaoxiaoMx> lq=new LambdaQueryWrapper<>();
        lq.eq(BaoxiaoMx::getReimbid,jsonObject.getString("bxid"));
      List<BaoxiaoMx>  list= reimbursementDetailsService.list(lq);
        ArrayList<Integer> list2=new ArrayList<>();
       for(BaoxiaoMx mx:list){
           list2.add(mx.getId());
       }
    int b=   reimbursementDetailsMapper.deleteBatchIds(list2);
//      报销 b=    reimbursementService.getById(lq);
//      b.getId();
       System.out.println(b);
        return ResultData.success(b);
    }
}
